//
//  ProjectsHelpersViewController.m
//  YYZB
//
//  Created by 顾悦 on 16/3/30.
//
//

#import "ProjectsHelpersViewController.h"

#import "ClientWebViewController.h"

@interface ProjectsHelpersViewController ()

@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
@property (strong, nonatomic) UIBarButtonItem *mapBarButtonItem;

@end

@implementation ProjectsHelpersViewController

#pragma mark -

- (UIBarButtonItem *)mapBarButtonItem {
    if (!_mapBarButtonItem) {
        _mapBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"map"] style:UIBarButtonItemStylePlain target:self action:@selector(mapBarButtonItemTapped)];
    }
    
    return _mapBarButtonItem;
}

#pragma mark -

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.titleView = self.segmentedControl;
    self.tabBar.hidden = YES;
    for (ProjectsHelpersChildViewController *c in self.viewControllers) {
        c.bizType = self.bizType;
        c.serviceID = self.serviceID;
        c.serviceName = self.serviceName;
        c.menuData = self.menuData;
        c.serviceSubCategoryID = self.serviceSubCategoryID;
        
        c.communityId = self.communityId;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -

//项目、帮工的点击事件
- (IBAction)segmentedControlValueChanged:(id)sender {
    self.selectedIndex = ((UISegmentedControl *)sender).selectedSegmentIndex;
    self.navigationItem.rightBarButtonItem = self.selectedIndex == 1 ? self.mapBarButtonItem : nil;
}

- (void)mapBarButtonItemTapped {
    ClientWebViewController *c = ClientWebViewController.new;
    c.HTMLURL = [NSString stringWithFormat:@"projects/helperMap.html?cate1Id=%@", self.serviceID];
    c.keepState = YES;
    [self.navigationController pushViewController:c animated:YES];
}

#pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    ProjectsHelpersChildViewController *c = (ProjectsHelpersChildViewController *)segue.destinationViewController;
    c.bizType = self.bizType;
    c.serviceID = self.serviceID;
    c.menuData = self.menuData;
}

@end
